package com.binguo.wxapi.controller;

import com.binguo.model.model.QucanguiUser;
import com.binguo.service.QucanguiUserService;
import com.binguo.wxapi.form.QucanguiUserForm;
import com.binguo.wxapi.form.QucanguiUserUpdateStatusForm;
import com.binguo.wxapi.result.Result;
import com.binguo.wxapi.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

/**
 * @author yuritian
 * @Title: WxQucanguiController
 * @ProjectName binguoDevelop
 * @Description: TODO
 * @date 2020/4/2419:59
 */
@Api(tags = "取餐柜设置")
@RestController
@RequestMapping
public class WxQucanguiController {

    @Resource
    QucanguiUserService qucanguiUserService;

    @PostMapping(value = "/api/wxapp/qucangui/modifyUser", produces = APPLICATION_JSON_VALUE)
    @ApiOperation(value = "取餐柜开柜管理员", notes = "通过CreateCardForm")
    public Result modifyUser(@RequestBody @Valid QucanguiUserForm form) {
        QucanguiUser user = new QucanguiUser();
        user.setPhone(form.getPhone());
        user.setName(form.getName());
        user.setStartTime(form.getStartTime());
        user.setEndTime(form.getEndTime());
        user.setBranchId(form.getBranchId());
        user.setDeskId(form.getDeskId());
        qucanguiUserService.ModifyQucanguiUser(user);
        return ResultGenerator.genSuccessResult();
    }


    @PostMapping(value = "/api/wxapp/qucangui/updateUserStatus", produces = APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改取餐柜开柜管理员状态", notes = "通过CreateCardForm")
    public Result updateUserStatus(@RequestBody @Valid QucanguiUserUpdateStatusForm form) {
        qucanguiUserService.deleteQucanguiUser(form.getBranchId(),form.getDeskId(),form.getPhone(),form.getStatus());
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping(value = "/api/wxapp/qucangui/getUserList", produces = APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改取餐柜开柜管理员状态", notes = "通过CreateCardForm")
    public Result getUserList(@RequestBody @Valid QucanguiUserUpdateStatusForm form) {
        return ResultGenerator.genSuccessResult(qucanguiUserService.getUserList(form.getBranchId(),form.getDeskId()));
    }

    @PostMapping(value = "/api/wxapp/qucangui/queryUserStatus", produces = APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改取餐柜开柜管理员状态", notes = "通过CreateCardForm")
    public Result queryUserList(@RequestBody @Valid QucanguiUserUpdateStatusForm form) {
        qucanguiUserService.queryCustomerStatus(form.getBranchId(),form.getDeskId(),form.getPhone());
        return ResultGenerator.genSuccessResult();
    }


}
